<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <style>
    *{
      margin: 0;
      padding: 0;
    }
    #di{
      width: 100px;
      height: 100px;
      background-color: yellow;
      position: absolute;
      top: 100px;
      left: 0;
    }
    #di1{
      width: 100px;
      height: 100px;
      background-color: red;
      position: absolute;
      top: 300px;
      left: 0;
    }
  </style>
</head>
<body>
  <input type="button" value="按钮" id="btn">
  <input type="button" value="停止" id="btn1">
  <input type="button" value="按钮500" id="btn2">
  <input type="button" value="停止500" id="btn3">
  <div id="di"></div>
  <div id="di1"></div>
  <script>
    var btn = document.getElementById("btn");
    var btn1 = document.getElementById("btn1");
    var btn2 = document.getElementById("btn2");
    var btn3 = document.getElementById("btn3");


    var di = document.getElementById("di");
    var di1 = document.getElementById("di1");


    // 从0移动 到500
    var set1 = 0;
    var dstep1 = 0;
    btn2.onclick = function () {
        clearInterval(set1);
      set1 = window.setInterval(function () {
        dstep1 += 53;
        // 判断运输是否到500的位置
        if (dstep1 >= 500) {
          // 先拉再赋值
          dstep1 = 500;
          clearInterval(set1);
        }
        di1.style.left = dstep1 + "px";
      },100)
    }
  </script>
</body>
</html>